package com.example.controller.admin;

import com.example.common.Result;
import com.example.entity.Course;
import com.example.entity.DTO.CourseDetailDTO;
import com.example.service.admin.AdminCourseService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminCourseController {
    @Resource
    private AdminCourseService adminCourseService;

    /**
     * 获取全部课程详细信息
     */
    @GetMapping("/selectAllCourse")
    public Result selectAllCourse(@RequestParam(defaultValue = "") String courseName,
                                  @RequestParam(defaultValue = "") String teacherName,
                                  @RequestParam(defaultValue = "") String deptName) {
        List<CourseDetailDTO> courseDetailDTOS = adminCourseService.selectAllCourse(courseName, teacherName, deptName);
        return Result.success(courseDetailDTOS);
    }

    /**
     * 根据课程名获取单个课程信息
     */
    @GetMapping("/selectCourse")
    public Result selectCourse(@RequestParam(defaultValue = "") String name) {
        Course course = adminCourseService.selectByName(name);
        return Result.success(course);
    }

    /**
     * 添加课程
     */
    @PostMapping("/addCourse")
    public Result addCourse(@RequestBody Course course) {
        adminCourseService.addCourse(course);
        return Result.success();
    }

    /**
     * 更新课程信息
     */
    @PutMapping("/updateCourse")
    public Result update(@RequestBody Course course) {
        adminCourseService.updateCourse(course);
        return Result.success();
    }

    /**
     * 删除课程
     */
    @DeleteMapping("/deleteCourse/{id}")
    public Result deleteCourse(@PathVariable Integer id) {
        adminCourseService.deleteCourse(id);
        return Result.success();
    }
}
